﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Globalization;

public partial class GUI_Pages_Admin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    static int dummy = 2;
    protected void Filter_Click(object sender, EventArgs e)
    {
        String area = filterbyarea.SelectedItem.Text;
        int langid = int.Parse(filterbylanguage.SelectedValue);
        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);


        if (area == "All" && langid == 0)
        {
            GridView1.DataSourceID = "SqlDataSource1";
            GridView1.DataBind();
            Label1.Visible = false;
        }
        else
        {
            String query = "";
            if (area == "All" && langid != 0)
            {
                query = "SELECT DISTINCT b.BSID, b.BSName, b.DoB, b.EMail, b.CellNo, b.Area " +
                    "FROM BabySitters b INNER JOIN BabySitters_Languages bl " +
                    "ON b.BSID = bl.BSID " +
                    "WHERE bl.LanguageID = @langid";

            }
            else if (area != "All" && langid == 0)
            {
                query = "SELECT DISTINCT b.BSID, b.BSName, b.DoB, b.EMail, b.CellNo, b.Area " +
                    "FROM BabySitters b INNER JOIN BabySitters_Languages bl " +
                    "ON b.BSID = bl.BSID " +
                    "WHERE b.Area = @area";

            }
            else if (area != "All" && langid != 0)
            {
                query = "SELECT DISTINCT b.BSID, b.BSName, b.DoB, b.EMail, b.CellNo, b.Area " +
                    "FROM BabySitters b INNER JOIN BabySitters_Languages bl " +
                    "ON b.BSID = bl.BSID " +
                    "WHERE b.Area = @area AND bl.LanguageID = @langid";

            }
            SqlCommand cmd1 = new SqlCommand(query, conn);
            cmd1.CommandType = CommandType.Text;
            cmd1.Parameters.Add(new SqlParameter("@area", area));
            cmd1.Parameters.Add(new SqlParameter("@langid", langid));
            SqlDataAdapter ad = new SqlDataAdapter(cmd1);

            conn.Open();
            cmd1.ExecuteNonQuery();
            conn.Close();

            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd1);
            da.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                Label1.Visible = true;
            }
            else
            {
                Label1.Visible = false;
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }


    }

    protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        int bsid = int.Parse(row.Cells[1].Text);

        //Response.Redirect("http://www.cairositters.com/GUI/Pages/BabysitterInfo.aspx?bsID=" + bsid + "&d=" + dummy);
        Response.Redirect("http://localhost:60070/CSWebSite_v1.0/GUI/Pages/BabysitterInfo.aspx?bsID=" + bsid + "&d=" +dummy);
    }

    protected void applicants_Click(object sender, EventArgs e)
    {
       
        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        SqlCommand cmd1 = new SqlCommand("SELECT b.BSID, b.BSName, b.CellNo, a.Interviewed, a.Approved " +
            "FROM BabySitters b INNER JOIN Accounts a ON b.AccountID = a.AccountID " +
            "WHERE a.Approved IS NULL", conn);
        cmd1.CommandType = CommandType.Text;

        conn.Open();
        cmd1.ExecuteNonQuery();
        conn.Close();

        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd1);
        da.Fill(dt);
        GridView1.DataSourceID = null;

        GridView1.Columns.Clear();
        GridView1.AutoGenerateColumns = true;
        CommandField cf = new CommandField();
        cf.ShowSelectButton = true;
        GridView1.Columns.Add(cf);
        GridView1.EmptyDataText = "No New Applicants";
        GridView1.DataSource = dt;
        GridView1.DataBind();
        dummy = 1;
    }
    protected void babysitters_Click(object sender, EventArgs e)
    {
        dummy = 2;
        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        SqlCommand cmd1 = new SqlCommand("SELECT b.BSID, b.BSName, b.CellNo, a.Interviewed, b.Trained, b.PaidTraining  " +
            "FROM BabySitters b INNER JOIN Accounts a ON b.AccountID = a.AccountID " +
            "WHERE a.Approved = 'True'", conn);
        cmd1.CommandType = CommandType.Text;
        SqlDataAdapter ad = new SqlDataAdapter(cmd1);

        conn.Open();
        cmd1.ExecuteNonQuery();
        conn.Close();

        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd1);
        da.Fill(dt);

        GridView1.DataSourceID = null;
        GridView1.Columns.Clear();
        GridView1.AutoGenerateColumns = true;
        CommandField cf = new CommandField();
        cf.ShowSelectButton = true;
        GridView1.Columns.Add(cf);
        //GridView1.Columns[6].HeaderText = "Paid for Training";
        GridView1.EmptyDataText = "No Babysitters";
        GridView1.DataSource = dt;
        GridView1.DataBind();

    }
}